<!--
 * @Date         : 2020-10-28 09:42:58
 * @LastEditors  : zhangyu
 * @LastEditTime : 2020-11-04 15:45:26
 * @Description  : 
-->
<template>
  <div class="table-box">
    <div class="page-header">权限管理</div>
	<el-button type="primary" @click="handleAdd" class="addBtn">新增权限组</el-button>
    <el-table :data="groups" style="width: 100%">
      <el-table-column prop="id" label="权限组编号" width="180"></el-table-column>
      <el-table-column prop="name" label="权限组名称"> </el-table-column>
      <el-table-column prop="create_time" label="创建时间"> </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button size="mini" @click="handleEdit(scope.$index, scope.row)"
            >编辑</el-button
          >
          <el-button size="mini" type="warning" @click="handleRole(scope.$index, scope.row)"
            >权限</el-button
          >
          <el-button
            size="mini"
            type="danger"
            @click="handleDelete(scope.$index, scope.row)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
export default {
  data() {
    return {
      groups: [],
    };
  },
  created() {
    this.getList()
  },
  methods: {
	  async getList(){
		  let res = await this.$http.get("group/list");
		  this.groups = res;
	  },
    handleEdit(idx, row) {
      this.$router.push("/group/edit/" + row.id);
    },
	handleAdd(){
		this.$router.push('/group/add')
	},
	handleRole(idx,row){
		this.$router.push('/group/role/'+row.id);
	},
    async handleDelete(idx, row) {
      await this.$confirm(
        `此操作将删除权限组「${row.name}」, 是否继续?`,
        "提示",
        { confirmButtonText: "确定", cancelButtonText: "取消", type: "warning" }
      );
	  await this.$http.post('/group/remove',{id:row.id});
	  this.getList()
    },
  },
};
</script>

<style scoped>
  
</style>
